package com.iflytek.sort;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class BestCountBean implements WritableComparable<BestCountBean> {

    private long comments;//评论数
    private long prices;//价格

    public BestCountBean() {
    }

    public BestCountBean(long comments, long prices) {
        this.comments = comments;
        this.prices = prices;
    }

    public void set(long comments, long prices) {
        this.comments = comments;
        this.prices = prices;
    }

    public long getComments() {
        return comments;
    }

    public void setComments(long comments) {
        this.comments = comments;
    }

    public long getPrices() {
        return prices;
    }

    public void setPrices(long prices) {
        this.prices = prices;
    }

    /**
     *  序列化方法
     */
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(comments);
        out.writeLong(prices);
    }

    /**
     * 反序列化方法 注意顺序
     */
    @Override
    public void readFields(DataInput in) throws IOException {
        this.comments = in.readLong();
        this.prices =in.readLong();
    }

    @Override
    public String toString() {
        return  comments +"\t"+ prices;
    }

    /**
     * 排序比较器  本业务中根据评论数倒序排序
     */
    @Override
    public int compareTo(BestCountBean o) {
        return this.comments - o.getPrices()> 0 ? -1:(this.comments - o.getPrices() < 0 ? 1 : 0);
    }
}